package com.lifeonwalden.dsg.service;

import com.lifeonwalden.dsg.bean.DateGenerateRule;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 内部工具类
 * <p>
 * 请勿直接使用
 */
public interface InnerDayFrequencyUtil {
    static List<Date> generate(DateGenerateRule rule, DateService dateService) {
        List<Date> dateList = new ArrayList<>();

        Instant date = rule.getStart().toInstant();
        Instant end = rule.getEnd().toInstant();
        do {
            InnerUtil.acceptValidDate(dateList, Date.from(date), rule, dateService);
            date = date.plus(rule.getStep(), ChronoUnit.DAYS);
        } while (date.compareTo(end) <= 0);

        return dateList;
    }
}
